package com.ms.demo;

import com.ms.demo.entity.Emp;
import com.ms.demo.mapper.EmpDataMapper;
import com.ms.demo.utils.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

/**
 * @description: 多对一映射查询 及 分布查询
 * @author: ms
 * @create: 2022-08-20 17:23
 */
public class MybatisMysqlTest3 {

    /**
    * @Description: getEmpAndDeptById1  级联方式处理映射关系
    * @Date: 2022/8/20 17:42
    */
    @Test
    public void getEmpAndDeptById1(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = sqlSession.getMapper(EmpDataMapper.class);
        Emp emp = mapper.getEmpAndDeptById1("1");
        System.out.println(emp);
    }

    /**
    * @Description: getEmpAndDeptById2  使用association处理映射关系
    * @Date: 2022/8/20 17:44
    */
    @Test
    public void getEmpAndDeptById2(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = sqlSession.getMapper(EmpDataMapper.class);
        Emp emp = mapper.getEmpAndDeptById2("1");
        System.out.println(emp);
    }

    /**
     * @Description: getEmpAndDeptById3  分步查询   延迟加载
     * @Date: 2022/8/20 17:44
     */
    @Test
    public void getEmpAndDeptById3(){
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = sqlSession.getMapper(EmpDataMapper.class);
        Emp emp = mapper.getEmpAndDeptById3("1");
        System.out.println(emp.getId());
       //System.out.println(emp.getDept().toString());  //测试延迟加载
    }
}